<template>
  <div v-show="visible">
    <div id="mainhead" >
      <transition v-show="visible" name="van-fade">
        <NavBar @showpop="showpop()" :navinfo="navinfo"></NavBar>
      </transition>
    </div>
    <div id="main" :style="{'max-height':slide_h}" style="overflow-y: auto">
      <div class="border-b">
        <van-field
          v-model="params.oldPassword"
          required
          clearable
          label="原始密码"
          type="password"
          placeholder="请输入旧密码"
        />
      </div>
      <div class="border-b">
        <van-field
          v-model="params.password"
          required
          clearable
          label="新密码"
          type="password"
          placeholder="请输入新密码"
        />
      </div>
      <div class="border-b">
        <van-field
          v-model="params.password2"
          required
          clearable
          label="确认密码"
          type="password"
          placeholder="请再次输入新密码"
        />
      </div>
      <div class="p-tb20"></div>
      <div class="p-lr-15">
        <van-button @click="submitForm()"
                    size="large" type="primary">立 即 修 改
        </van-button>
      </div>
    </div>
    <van-popup id="editBank" :lazy-render="1==0" class="popbg" style="width:86%" v-model="popshow">
      <div class="p-tb10 text-center">重置密码申请</div>
      <div class="border-b">
        <van-field
          v-model="resetParams.reason"
          required
          clearable
          label="申请原因"
          type="textarea"
          placeholder="请填写重置原因"
        />
      </div>
      <div class="border-b">
        <van-field
          v-model="resetParams.password"
          required
          clearable
          minlength="6"
          maxlength="20"
          label="新密码"
          type="password"
          placeholder="请输入新密码"
        />
      </div>
      <div class="border-b">
        <van-field
          v-model="resetParams.password2"
          required
          clearable
          minlength="6"
          maxlength="20"
          label="确认密码"
          type="password"
          placeholder="请再次输入新密码"
        />
      </div>
      <div class="p-tb20"></div>
      <div class="p-lr-15">
        <van-button @click="submitReset()"
                    size="large" type="primary">立 即 申 请
        </van-button>
      </div>
      <div class="p-tb5">&nbsp;</div>
    </van-popup>
  </div>
</template>
<script>
  const NavBar = () =>
    import ('@/components/header/NavBar');
  export default {
    name: "memberPwd",
    components: {
      'NavBar': NavBar,
    },
    data() {
      return {
        visible: false,
        navinfo: {
          title: '密码管理',
          leftText: '返回',
          leftIcon: '',
          leftLink: '',
          rightText: '申请重置',
          rightIcon: '',
          rightLink: 'showpop'
        },
        slide_h: (window.document.body.offsetHeight - 50) + "px",
        popshow: false,
        params:{
          oldPassword: '',
          password: '',
          password2: '',
        },
        resetParams:{
          reason:'',
          password:'',
          password2: '',
        }
      }
    },
    methods: {
      submitForm() {
        if(this.params.oldPassword==''){
          this.proUtil.msgInfo('请输入原始密码');
          return ;
        }
        if(this.params.password==''||this.params.password!=this.params.password2){
          this.proUtil.msgInfo('两次输入的密码不一致');
          return ;
        }
        var m = {
          oldPassword: this.proUtil.md5(this.proUtil.md5(this.params.oldPassword)),
          password: this.proUtil.md5(this.proUtil.md5(this.params.password)),
        };
        this.proAPI.postJson(this.proAPI.URLS.modifyMemberPwd, m).then((res) => {
          this.proUtil.msgSuccess(res.message);
          setTimeout(()=>{
            this.$router.go(-1);
          },1500)
        })
      },
      showpop(){
        this.popshow = true;
      },
      submitReset(){
        if(this.resetParams.reason==''){
          this.proUtil.msgInfo('请输入重置原因');
          return ;
        }
        if(this.resetParams.password==''||this.resetParams.password!=this.resetParams.password2){
          this.proUtil.msgInfo('两次输入的密码不一致');
          return ;
        }
        var m = {
          reason:this.resetParams.reason,
          password: this.proUtil.md5(this.proUtil.md5(this.resetParams.password)),
        }


        this.$store.commit("saveLoadingMap", {
          "target": this.proAPI.URLS.resetMemberPwd,
          lock: 1
        });
        this.proAPI.postJson(this.proAPI.URLS.resetMemberPwd,m).then((res) => {
          this.proUtil.msgSuccess(res.message);
          setTimeout(() => {
            this.popshow = false;
          }, 1000)
        })
      }
    },
    beforeCreate: function () {
    },
    created: function () {
    },
    beforeMount: function () {
    },
    mounted: function () {
      setTimeout(() => {
        this.visible = true;
      }, 200)
    },
    beforeUpdate: function () {
    },
    updated: function () {
    },
    activated: function () {
    },
    deactivated: function () {
    },
    beforeDestroy: function () {
    },
    destroyed: function () {
    },
    errorCaptured: function (err, vm, info) {
    }
  }
</script>
<style scoped>
</style>
